package com.atguigu.eduService.api;

import com.atguigu.commonutils.R;
import com.atguigu.eduService.entity.EduCourse;
import com.atguigu.eduService.entity.EduTeacher;
import com.atguigu.eduService.service.EduCourseService;
import com.atguigu.eduService.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "首页显示")
@RestController
@RequestMapping("/eduService/index")
@CrossOrigin
public class indexController {
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    @ApiOperation(value = "首页面展示课程，讲师信息")
    @GetMapping("getTeacherCourseList")
    public R getTeacherCourseList(){
        QueryWrapper<EduCourse> courseWrapper=new QueryWrapper<>();
        courseWrapper.orderByDesc("gmt_modified");
        courseWrapper.last("Limit 8");
        List<EduCourse> coursesList = courseService.list(courseWrapper);
        QueryWrapper<EduTeacher> teacherWrapper=new QueryWrapper<>();
        teacherWrapper.orderByDesc("gmt_modified");
        teacherWrapper.last("Limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherWrapper);
        return  R.ok().data("coursesList",coursesList).data("teacherList",teacherList);

    }

}
